<?php

class Confirm_goods_info extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Confirm_goods_info':
	 * @var integer $id
	 * @var integer $fk_confirm_id
	 * @var string $goods_name
	 * @var integer $fk_consignor_id
	 * @var integer $fk_consignee_id
	 * @var string $fuel_name
	 * @var double $amount
	 * @var integer $unit_name
	 * @var integer $pack_type
	 * @var integer $time_costing
	 * @var integer $lift_kind
	 * @var string $loading_place
	 * @var string $pod_place
	 * @var string $demand_deliver_time
	 * @var string $demand_arrival_time
	 * @var string $consignor_name
	 * @var string $consignee_name
	 * @var integer $state
	 * @var string $create_time
	 */
	
	public $driver_salary;
	
	private $_pack_type=array('0'=>'托盘','1'=>'散装','2'=>'盒装','3'=>'袋装');
	private $_time_costing=array('0'=>'2小时','1'=>'4小时','2'=>'6小时','3'=>'8小时','4'=>'10小时','5'=>'12小时','6'=>'14小时',
	'7'=>'16小时','8'=>'18小时','9'=>'20小时','10'=>'22小时','11'=>'24小时');
	private $_lift_kind=array('0'=>'机力' ,'1'=>'人力', '2'=>'机力配人力');
	private $_shortage=array('0'=>'否','1'=>'是');
	private $_arrival_state=array('0'=>'完好','1'=>'破损','2'=>'雨淋');
	private $_special_state=array('0'=>'无','1'=>'货损原因','2'=>'道路原因','3'=>'天气原因');
	
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'confirm_goods_info';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('fuel_name','length','max'=>20),
			array('loading_place','length','max'=>40),
			array('pod_place','length','max'=>40),
			array('consignor_name','length','max'=>100),
			array('consignee_name','length','max'=>100),
			array('actual_consignee','length','max'=>100),
			array('special_state_detail','length','max'=>50),
			array('goods_name','length','max'=>20),
			//array('unit_name, pack_type, time_costing, lift_kind', 'numerical', 'integerOnly'=>true),
			array('amount', 'numerical'),
			array('driving_circuit', 'numerical', 'integerOnly'=>true),
			array('amount,loading_place,pod_place,demand_deliver_time,demand_arrival_time,actual_arrival_time,consignor_link_name,consignor_link_tel,
			consignee_link_name,consignee_link_tel,origin,destination,path_mileage,consignor_name,consignee_name,actual_consignee,
			fuel_name,unit_name,pack_type,time_costing,lift_kind,goods_name,driving_circuit,shortage,arrival_state,special_state,driver_salary', 'required'),
			array('amount', 'match','pattern' => '/^\d{1,8}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多8位，小数位2位'),
			array('driver_salary', 'match','pattern' => '/^\d{1,16}(\.\d{1,2})?$/','message'=>'{attribute} 整数位最多16位，小数位2位'),
			array('demand_deliver_time,demand_arrival_time,actual_arrival_time', 'match','pattern' => '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/','message'=>'{attribute} 必须为日期型(年-月-日  时:分)'),
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'fk_confirm_id' => '确认单id',
			'goods_name' => '货物名称',
			'fk_consignor_id' => '货主(发货人)id',
			'fk_consignee_id' => '客户(收货人)id',
			'fuel_name' => '标准油耗',//对应标准油耗表内8种状况之一 plain_empty、ghat_empty、plain_min.....
			'amount' => '货物数量',
			'unit_name' => '计算标准',// 0车 1托 2吨 3方 4吨公里 5其他
			'pack_type' => '包装类型',//0托盘 1散装 2盒装 3袋装
			'time_costing' => '装卸时间',//0:2小时 1:4小时...11:24小时
			'lift_kind' => '装卸类别',//0机力 1人力 2机力配人力
			'loading_place' => '装货地',
			'pod_place' => '卸货地',
			'demand_deliver_time' => '要求提货时间',
			'demand_arrival_time' => '要求送达时间',
			'actual_arrival_time' => '实际送达时间',
			'consignor_link_name' => '货主联系人',
			'consignor_link_tel' => '货主联系人电话',
			'consignee_link_name' => '客户联系人',
			'consignee_link_tel' => '客户联系人电话',
			'origin'=>'始发地',
			'destination'=>'目的地',
			'path_mileage'=>'运输里程',
			'driver_salary' =>'司机绩效',
			'driving_circuit' => '行驶线路', //0高速 1国道 2辅路
			'consignor_name'=>'货主(发货人)',
			'consignee_name'=>'客户(收货人)',
			'actual_consignee'=>'实际客户(收货人)',
			'shortage'=>'是够短缺',
			'arrival_state'=>'收货情况',
			'special_state'=>'特殊情况处理',
			'special_state_detail'=>'具体特殊情况',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
	
	public function getFuelNames(){
		return Yii::app()->params['fuel_consumption'];
	}
	
	public function getFuelName($n=null){
		return Yii::app()->params['fuel_consumption'][$n==null?$this->fuel_name:$n];
	}
	
	public function getUnitNames(){
		return Yii::app()->params['unit_name'];
	}
	
	public function getUnitName($n=null){
		return Yii::app()->params['unit_name'][$n==null?$this->unit_name:$n];
	}
	
	public function getPackTypeNames(){
		return $this->_pack_type;
	}
	
	public function getPackTypeName($n=null){
		return $this->_pack_type[$n==null?$this->pack_type:$n];
	}
	
	public function getTimeCostingNames(){
		return $this->_time_costing;
	}	
	
	public function getTimeCostingName($n=null){
		return $this->_time_costing[$n==null?$this->time_costing:$n];
	}	
	
	public function getLiftKindNames(){
		return $this->_lift_kind;
	}
	
	public function getLiftKindName($n=null){
		return $this->_lift_kind[$n==null?$this->lift_kind:$n];
	}
	
	public function getDrivingCircuitNames(){
		return Yii::app()->params['driving_circuit'];
	} 
	
	public function getDrivingCircuitName($n=null){
		return  Yii::app()->params['driving_circuit'][$n==null?$this->driving_circuit:$n];
	}
	
	public function getShortageNames(){
		return $this->_shortage;
	}
	
	public function getShortageName($n=null){
		return $this->_shortage[$n==null?$this->shortage:$n];
	}
	
	public function getArrivalStateNames(){
		return $this->_arrival_state;
	}
	
	public function getArrivalStateName($n=null){
		return $this->_arrival_state[$n==null?$this->arrival_state:$n];
	}
	
	public function getSpecialStateNames(){
		return $this->_special_state;
	}
	
	public function getSpecialStateName($n=null){
		return $this->_special_state[$n==null?$this->special_state:$n];
	}
	
	public function safeAttributes(){
		$params=parent::safeAttributes();
		return $params;
	}
}